<template>



	<div class="system-userDataDimensionEdit-dialog-container">
		<el-dialog :title="state.dialog.title" v-model="state.dialog.isShowDialog" width="1300px">
			<el-card shadow="hover">
				<div class="bar_tools">
					<div>数据权限</div>
				</div>
				<el-table size="default" :data="state.dataList" style="width: 100%">
					<el-table-column width="200" label="数据编码">
						<template #default="scope">
							<span>{{ scope.row.dataDimension }}</span>
						</template>
					</el-table-column>

					<el-table-column label="用户类型" prop="userType">
						<template #default="scope">
							<el-tag type="success"> {{
								getDic("dataDimensionList", scope.row.dataDimension)
							}}</el-tag>
						</template>
					</el-table-column>




					<el-table-column label="维度值" prop="dataDimensionValue">
					</el-table-column>
					<el-table-column label="数据来源">
						<template #default="scope">
							<el-tag type="success">{{
								scope.row.dataDimensionType == 10 ? "角色" : "用户"
							}}</el-tag>
						</template>
					</el-table-column>
					<el-table-column label="数据来源ID" prop="referId"> </el-table-column>
				</el-table>
			</el-card>



		</el-dialog>

	</div>
</template>

<script setup lang="ts" name="systemDicDialog">
import { ElMessage } from 'element-plus';
import { reactive, ref, watch } from 'vue';


// 导入接口
import { useSysApi } from "../../../api/sys";





const state = reactive({
	row: {} as any,
	dataDimensionList: [] as any,
	// 参数请参考 `/src/router/route.ts` 中的 `dynamicRoutes` 路由菜单格式
	dataList: [] as any,
	dialog: {
		isShowDialog: false,
		type: '',
		title: '',
		submitTxt: '',
	},
});




// 打开弹窗
const openDialog = async (row: any) => {
	state.row = row;
	state.dialog.title = "用户名：" + row.userName;
	state.dialog.isShowDialog = true;
	selectDicItemsByDicCode();
	queryUserDataDimensionListByUserId();
};
// 关闭弹窗
const closeDialog = () => {
	state.dialog.isShowDialog = false;
};


const queryUserDataDimensionListByUserId = async () => {
	state.dataList = await useSysApi().queryUserDataDimensionListByUserId(state.row.id);
}



const selectDicItemsByDicCode = async () => {
	state.dataDimensionList = await useSysApi().selectDicItemsByDicCode("data_dimension", "General");
}


const getDic = (obj: any, str: string) => {
	let strTemp = str;

	state[obj.toString()].forEach((element: any) => {
		if (element.dicItemValue == str) {
			strTemp = element.dicItemName;
		}
	});
	return strTemp;
}



watch(
	() => state.dialog.isShowDialog,
	(newValue) => {
		if (newValue == true) {
			// selectDicItemsByDicCode();
			// queryUserDataDimensionListByUserId();
		}
	}, { immediate: true }
);




// 暴露变量
defineExpose({
	openDialog,
});
</script>

<style lang="scss">
.el-select {
	width: 100% !important;
}



.system-userDataDimensionEdit-dialog-container {
	.bar_tools {
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-bottom: 10px;
	}

	.el-table__expanded-cell {
		padding: 20px;
	}
}
</style>